home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3397 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  87 lines

  1. Path: gryphon.phoenix.net!usenet
  2. From: brucew@phoenix.net (Bruce Wedding)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Function to calculate the Holy Easter
  5. Date: Sun, 28 Jan 1996 18:55:16 GMT
  6. Organization: BranPaul Systems
  7. Message-ID: <4egei9$8mi@gryphon.phoenix.net>
  8. References: <4ea7s9$q44@leporello.cs.unibo.it>
  9. NNTP-Posting-Host: dial77.phoenix.net
  10. X-Newsreader: Moe's Newsreader    
  11.  
  12. chierici@cs.unibo.it (Andrea Chierici) wrote:
  13.  
  14. >can anybody send me the C function to calculate the day of the Easter given
  15. >the year?
  16.  
  17.  
  18. /*
  19. **  EASTER.C - Determine the date of Easter for any given year
  20. **
  21. **  public domain by Ed Bernal
  22. */
  23.  
  24. void easter(int year, int *easter_month, int *easter_day);
  25.  
  26. #include <stdlib.h>
  27.  
  28. void easter(int year,int *easter_month, int *easter_day)
  29. {
  30.       int a,b,c,e,g,h,i,k,u,x,z;
  31.       div_t f;
  32.  
  33.       /*
  34.       **  Gauss' famous algorithm (I don't know how or why it works,
  35.       **  so there's no commenting)
  36.       */
  37.  
  38.       a = year % 19;
  39.       f = div(year,100);
  40.       b = f.quot;
  41.       c = f.rem;
  42.       f = div(b,4);
  43.       z = f.quot;
  44.       e = f.rem;
  45.       f = div((8*b + 13),25);
  46.       g = f.quot;
  47.       f = div((19*a + b - z - g + 15),30);
  48.       h = f.rem;
  49.       f = div((a + 11*h),319);
  50.       u = f.quot;
  51.       f = div(c,4);
  52.       i = f.quot;
  53.       k = f.rem;
  54.       f = div((2*e + 2*i - k - h + u + 32),7);
  55.       x = f.rem;
  56.       f = div((h-u+x+90),25);
  57.       *easter_month = f.quot;
  58.       f = div((h-u+x + *easter_month +19),32);
  59.       *easter_day = f.rem;
  60. }
  61.  
  62. #ifdef TEST
  63.  
  64. #include <stdio.h>
  65.  
  66. main(int argc, char *argv[])
  67. {
  68.       int yr, mo, dy;
  69.  
  70.       while (--argc)
  71.       {
  72.             yr = atoi(*++argv);
  73.             if (100 > yr)
  74.                   yr += 1900;
  75.             easter(yr, &mo, &dy);
  76.             printf("Easter in %d on %d/%d\n", yr, mo, dy);
  77.       }
  78.       return 0;
  79. }
  80.  
  81. #endif /* TEST */
  82.  
  83. Bruce D. Wedding                        Have Compiler, Will Travel!
  84.               Perspicacious Programming Performed Promptly
  85. Katy, Texas, USA, Planet Earth, Milkyway Galaxy, Known Universe
  86.  
  87.